#!/bin/ksh

# parse arguments
i=1
for PARAM in "$@"; do
	{ read NAME OPT JUNK; NAMES[$i]="$NAME"; OPTS[$i]="$OPT"; } <<- EOF
		$PARAM
	EOF
	(( i += 1 )) || true
done

# check temp
while read TEMP JUNK; do
	{ IFS='=' read SENSOR TEMP; } <<- EOF
		$TEMP
	EOF
	i=1
	for NAME in "${NAMES[@]}"; do
		[[ "hw.sensors.admtemp0.$NAME" == "$SENSOR" ]] && TEMPS[$i]="$TEMP"
		(( i += 1 )) || true
	done
done <<- EOF
	$(sysctl hw.sensors.admtemp0)
EOF

# out
i=1
for NAME in "${NAMES[@]}"; do
	echo "generic,g,$NAME,${OPTS[$i]},${TEMPS[$i]}"
	(( i += 1 )) || true
done

